import { VNode } from './vnode'

export type PreHook = () => any
export type InitHook = (vNode: VNode) => any
export type CreateHook = (emptyVNode: VNode, vNode: VNode) => any
export type InsertHook = (vNode: VNode) => any
export type PrePatchHook = (oldVNode: VNode, vNode: VNode) => any
export type UpdateHook = (oldVNode: VNode, vNode: VNode) => any
export type PostPatchHook = (oldVNode: VNode, vNode: VNode) => any
export type DestroyHook = (vNode: VNode) => any
export type RemoveHook = (vNode: VNode, removeCallback: () => void) => any
export type PostHook = () => any

export interface Hooks {
  // patch 函数开始执行的时候触发
  pre?: PreHook
  // createElem 函数开始之前的时候触发
  // 在把VNode 转换成真实 DOM 之前触发
  init?: InitHook
  // createElm 函数末尾调用
  // 创建完真实DOM后触发
  create?: CreateHook
  // patch函数末尾执行
  // 真实DOM添加到DOM树种触发
  insert?: InsertHook
  // patchVnode 函数开头调用
  // 开始对比两个VN的差异之前触发
  prepatch?: PrePatchHook
  // patchVnode 函数开头调用
  // 两个VNode对比过程中触发，比prepatch 稍晚
  update?: UpdateHook
  // patchVnode 最末尾调用
  // 两个Vnode对比结束执行
  postpatch?: PostPatchHook
  // removeVnodes -> invokeDestroy 中调用
  // 在删除元素之前触发，子节点的destroy 也被触发
  destroy?: DestroyHook
  // removeVnodes 中调用
  // 元素被删除的时候触发
  remove?: RemoveHook
  // patch函数的最后调用
  post?: PostHook
}
